
from sys import argv
import os


try:
	print "try a girdi"
	f = open("dbtrainer.py", "r+")
except:
	print "excepte girdi"
	#os.popen2("touch dbtrainer.py")
	f = open("dbtrainer.py", "w+")

counter, first, second=0,0,0

s=f.readlines()

for x in s:
	if x.find("insertyazarlink") != -1: first=counter
	else: counter += 1
	
ss=s[first:]

counter=0

for x in ss:
	if x.find("except") != -1: 
		second=counter
		break
	else: counter += 1
try:	
	index = second-1
	prepost=ss[index].split("y.save()")	
	

	strng=prepost[0]+"y=c(yazaradi="+'"'+argv[1]+" "+argv[2]+'"'+", yazarlinki="+'"'+argv[3]+'"'+")"+prepost[1]
	strng=strng+prepost[0]+"y.save()"+prepost[1]

	ss.insert(index+1, strng)

except:

	pass

f.close()

li=s[:first]+ss

os.remove("dbtrainer.py")

g=open("dbtrainer.py", "w+")
print "ok"

for x in li:
	g.write(x)
	
g.close()